package com.ruoyi.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.Welfareinstitution;
import com.ruoyi.service.IWelfareinstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * WelfareinstitutionController
 * 
 * @author wjy
 * @date 2025-01-11
 */
@RestController
@RequestMapping("/welfareinstitution")
public class WelfareinstitutionController extends BaseController
{
    @Autowired
    private IWelfareinstitutionService welfareinstitutionService;

    /**
     * 查询Welfareinstitution列表
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:list")
    @GetMapping("/list")
    public TableDataInfo list(Welfareinstitution welfareinstitution)
    {
        startPage();
        List<Welfareinstitution> list = welfareinstitutionService.selectWelfareinstitutionList(welfareinstitution);
        return getDataTable(list);
    }

    /**
     * 导出Welfareinstitution列表
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:export")
    @Log(title = "Welfareinstitution", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Welfareinstitution welfareinstitution)
    {
        List<Welfareinstitution> list = welfareinstitutionService.selectWelfareinstitutionList(welfareinstitution);
        ExcelUtil<Welfareinstitution> util = new ExcelUtil<Welfareinstitution>(Welfareinstitution.class);
        util.exportExcel(response, list, "Welfareinstitution数据");
    }

    /**
     * 获取Welfareinstitution详细信息
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:query")
    @GetMapping(value = "/{institutionId}")
    public AjaxResult getInfo(@PathVariable("institutionId") Long institutionId)
    {
        return success(welfareinstitutionService.selectWelfareinstitutionByInstitutionId(institutionId));
    }

    /**
     * 新增Welfareinstitution
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:add")
    @Log(title = "Welfareinstitution", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Welfareinstitution welfareinstitution)
    {
        return toAjax(welfareinstitutionService.insertWelfareinstitution(welfareinstitution));
    }

    /**
     * 修改Welfareinstitution
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:edit")
    @Log(title = "Welfareinstitution", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Welfareinstitution welfareinstitution)
    {
        return toAjax(welfareinstitutionService.updateWelfareinstitution(welfareinstitution));
    }

    /**
     * 删除Welfareinstitution
     */
    @RequiresPermissions("welfareinstitution:welfareinstitution:remove")
    @Log(title = "Welfareinstitution", businessType = BusinessType.DELETE)
	@DeleteMapping("/{institutionIds}")
    public AjaxResult remove(@PathVariable Long[] institutionIds)
    {
        return toAjax(welfareinstitutionService.deleteWelfareinstitutionByInstitutionIds(institutionIds));
    }
}
